<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <div>
      <h1>The Ajax 03 Page</h1>
      <button onclick="doAjaxGet()">Do Ajax Get</button>
      <button onclick="doAjaxPost()">Do Ajax Post</button>
      <button onclick="doAjaxPostJson()">Do Ajax Post Json</button>
      <button onclick="doAjaxDelete()">Do Ajax Delete</button>
      <button onclick="doAjaxPut()">Do Ajax Put</button>
      <button onclick="doAjax()">Do Ajax</button>
  </div>
  <div id="result"></div>
  <script src="/js/ajax.js"></script>
  <script>
      function doAjax(){
         ajax({
             requestUrl:"/doAjaxPost",
             requestParams:"id=105&city=guangzhou",
             requestMethod:"POST",
             callback:function(result){
                 document.querySelector("#result").innerHTML=result;
             }
          });
      }
      //ajax delete request
      function doAjaxDelete(){
          const url="/doAjaxDelete";
          const params="101";
          ajaxDelete(url,params,function(result){//回调函数
              alert(result);
          })
      }
      //ajax post put
      function doAjaxPut(){
          const url="/doAjaxPut";
          const params="id=100&city=shenzhen";
          ajaxPut(url,params,function(result){//回调函数
              alert(result);
          })
      }
      //ajax post request
      function doAjaxPostJson(){
          const url="/doAjaxPostJSON";
          const params={id:"103",city:"xiongan"};//服务端需要@RequestBody
          ajaxPostJSON(url,params,function(result){//回调函数
              alert(result);
          })
      }
      //ajax post request
      function doAjaxPost(){
          const url="/doAjaxPost";
          const params="id=102&city=shenzhen";
          ajaxPost(url,params,function(result){//回调函数
              alert(result);
          })
      }
      //ajax get request
      function doAjaxGet(){
          const url="/doAjaxGet";
          const params="";
          ajaxGet(url,params,function(result){//回调函数
              document.querySelector("#result").innerHTML=result;
          });//封装了ajax操作的四个步骤
      }

  </script>
</body>
</html>